<?php

function search_item($query){

        //array: search is key to an array holding 
        //[key]:title
        //[0]:url
        //[1]:price
        //[2]:availability
        //[3]:shipping
        //[4]:description
        $items_map = array();
        //item_info is second array holding 0-5
        $item_info = array();
        $json = file_get_contents('https://www.googleapis.com/shopping/search/v1/public/products?country=US&q=$item_name&key=AIzaSyD9Q_CiH2WCrGJWUsTkUL8olEYCEMDhSpo');
        $json_data = json_decode($json);

        //echo $json_data->{'selfLink'};
        $items = $json_data->{'items'};

        foreach($items as $item){
                $product = $item->{'product'};

                $images = $product->{'images'};
                foreach($images as $image){
                        $first = $image->{'link'};

                        
                        //assign values to array
                        //NOT DONE HERE.
                        $item_info['url']=$first;
                        $inventory_info=$product->{'inventories'};
                        foreach($inventory_info as $info){
                            $item_info['price'] = $info->{'price'};
                            $item_info['availability'] = $info->{'availability'};
                            $item_info['shipping'] = $info->{'shipping'};
                            $item_info['description'] = $product->{'description'};
                        }
                
                }
                //store the value according to the title
                
                $item_name = $product->{'title'};

                $items_map[$item_name] = $item_info;                
                
                


                foreach($items_map as $n=>$v){
                        echo 'Title: ' . $n . '<br>';
                    echo 'URL: ' . $v['url'] . '<br>';
                    echo 'Price: ' . $v['price'] . '<br>';
                    echo 'Availability ' . $v['availability'] . '<br>';
                    echo 'Shipping ' . $v['shipping'] . '<br>';
                    echo 'Description: ' . $v['description'] . '<br>';

                }

        }

    
}





search_item('boots');
?>
